<template>
  <div class="fu-channel">
    <el-row>
      <ul class="fz12" style="line-height: 2;">
        <li>经营地址：{{ date.area }}</li>
        <li>详细地址：{{ date.address }}</li>
        <li>门店名称：{{ date.mch_short_name }}</li>
        <li>行业类型：{{ date.mcc }}</li>
        <li>渠道选择：{{ date.balance_type }}</li>
        <li v-if="date.card === 3"><h4>POS机支付</h4></li>
        <li v-if="date.card === 3">借记卡D+1费率：{{ date.credit_d1 }} %</li>
        <li v-if="date.card === 3">借记D+1封顶金额：{{ date.debit_money }} 元</li>
        <li v-if="date.card === 3">借记卡D+0费率：{{ date.credit_d0 }} %</li>
        <li v-if="date.card === 3">贷记卡D+1费率：{{ date.debit_d1 }} %</li>
        <li v-if="date.card === 3">贷记卡D+0费率：{{ date.debit_d0 }} %</li>
        <li v-if="date.card === 3">境外卡D+0费率：{{ date.ovsea_d0 }} %</li>
        <li v-if="date.card === 3">境外卡D+1费率：{{ date.ovsea_d1 }} %</li>
        <li v-if="date.card === 3"><span style="vertical-align: top;">证件信息：</span>
          <img width="100" height="100" title="租赁协议或房产证明" v-if="date.photo.channel_lepos_place_evid" :src="date.photo.channel_lepos_place_evid" @click="handleClickZoomImg(date.photo.channel_lepos_place_evid)">
          <img width="100" height="100" title="入网协议" v-if="date.photo.channel_lepos_netprot" :src="date.photo.channel_lepos_netprot" @click="handleClickZoomImg(date.photo.channel_lepos_netprot)">
          <img width="100" height="100" title="食品卫生许可证" v-if="date.photo.store_licence_hyg" :src="date.photo.store_licence_hyg" @click="handleClickZoomImg(date.photo.store_licence_hyg)">
          <img width="100" height="100" title="协议书" v-if="date.photo.ch_lpos_certi" :src="date.photo.ch_lpos_certi" @click="handleClickZoomImg(date.photo.ch_lpos_certi)">
        </li>
        <li><h4>移动支付</h4></li>
        <li>微信通道签约费率T+0：{{ date.rates_t0.wx }} %</li>
        <li>微信通道签约费率T+1：{{ date.rates_t1.wx }} %</li>
        <li>支付宝通道签约费率T+0：{{ date.rates_t0.ali }} %</li>
        <li>支付宝通道签约费率T+1：{{ date.rates_t1.ali }} %</li>
      </ul>
    </el-row>
    <el-row>
      <el-col :span="23" :offset="1">
        <el-button type="primary" size="small" @click="handleClickOnSubmit(200)">通过并提交审核</el-button>
        <el-button type="danger" size="small" @click="handleClickOnSubmit(-200)">不通过</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { verfiryChannelLeValid, verfiryChannelLeQuery } from '@/api/shop'

export default {
  data() {
    return {
      date: {
        card: null,
        area: '',
        address: '',
        mcc: '',
        balance_type: '',
        debit_d1: '',
        debit_d0: '',
        credit_d1: '',
        credit_d0: '',
        ovsea_d1: '',
        ovsea_d0: '',
        debit_money: '',
        photo: {},
        rates_t0: {},
        rates_t1: {},
        channel_status: null
      }
    }
  },
  methods: {
    handleDocumentInit() {
      verfiryChannelLeQuery(this.$route.query.id).then(res => {
        if (res.data.errorCode === 0) {
          this.date.card = res.data.result.card
          this.date.area = res.data.result.area.name.toString()
          this.date.address = res.data.result.address
          this.date.mcc = res.data.result.mcc.name
          this.date.mch_short_name = res.data.result.mch_short_name
          this.date.balance_type = res.data.result.balance_type
          this.date.credit_d1 = Number(res.data.result.pos_rates.credit.d1.rate)
          this.date.credit_d0 = Number(res.data.result.pos_rates.credit.d0.rate)
          this.date.debit_d1 = Number(res.data.result.pos_rates.debit.d1.rate)
          this.date.debit_d0 = Number(res.data.result.pos_rates.debit.d0.rate)
          this.date.ovsea_d0 = Number(res.data.result.pos_rates.ovsea.d0.rate)
          this.date.ovsea_d1 = Number(res.data.result.pos_rates.ovsea.d1.rate)
          this.date.debit_money = Number(res.data.result.pos_rates.debit.d1.ceiling)
          this.date.photo = res.data.result.photo
          this.date.rates_t0 = res.data.result.rates_t0
          this.date.rates_t1 = res.data.result.rates_t1
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    },
    handleClickOnSubmit(status) {
      if (status === -200) {
        this.$msgbox({
          title: '拒绝原因',
          showInput: true,
          inputType: 'textarea',
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showCancelButton: true
        }).then(({ value }) => {
          verfiryChannelLeValid(this.$route.query.id, status, value).then(res => {
            if (res.data.errorCode === 0) {
              this.$message.success(res.data.errorMsg)
              this.$emit('update')
            } else {
              this.$message.error(res.data.errorMsg)
            }
          })
        }).catch(() => {
          return false
        })
      } else {
        verfiryChannelLeValid(this.$route.query.id, status).then(res => {
          if (res.data.errorCode === 0) {
            this.$message.success(res.data.errorMsg)
            this.$emit('update')
          } else {
            this.$message.error(res.data.errorMsg)
          }
        })
      }
    },
    handleClickZoomImg(url) {
      this.$alert(`<img width="100%" heigth="100%" src= ${url}></img>`, {
        dangerouslyUseHTMLString: true,
        center: true,
        showConfirmButton: false,
        closeOnClickModal: true,
        closeOnPressEscape: true
      }).then(() => {
        return false
      }).catch(() => {
        return false
      })
    }
  },
  created() {
    this.handleDocumentInit()
  }
}
</script>